// pages/my/my.js
const interfaces = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasUserInfo: false,
    getUser: {},
    collectGoodList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (!res.authSetting['scope.userInfo']) {
          wx.navigateTo({
            url: '/pages/login/login'
          })
        }else{
          this.getCollect()
        }
      }
    })
  },
  getCollect() {
    const self = this
    wx.showLoading({
      title: '',
    })
    let openId = wx.getStorageSync('openId')
    wx.request({
      url: interfaces.collectList,
      data: {
        openId: openId
      },
      success(res) {
        wx.hideLoading()
        //console.log(res)
        self.setData({
          collectGoodList: res.data.collectGoodsList
        })
      }
    })
  },
  tologin(){
    wx.navigateTo({
      url: '/pages/login/login'
    })
  },
  /**
   * 跳转到我的收藏
   */
  myCollection(){
    wx.navigateTo({
      url: '/pages/collectList/collectList'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  toAddressList(){
    wx.navigateTo({
      url: '/pages/address/address'
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let login = wx.getStorageSync('isLogin');
    let user = wx.getStorageSync('user');
    if(login && user){
      this.setData({
        hasUserInfo: login,
        getUser: user
      })
    }else{
      this.setData({
        hasUserInfo: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})